﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XYZshell.Game.CardGameEngine
{
	/// <summary>
	/// 简单表达式
	/// </summary>
	[Condition("simple")]
	public  class SimpleCondition:BaseCondition
	{
		public SimpleCondition()
		{
			Expression=new DirectValueExpression(true);
		}
		public SimpleCondition( bool value )
		{
			Expression = new DirectValueExpression( value );
		}
		/// <summary>
		/// 包含的表达式
		/// </summary>
		public BaseExpression Expression
		{
			get;
			set;
		}
		/// <summary>
		/// 简单表达式的值
		/// </summary>
		/// <returns></returns>
		public override bool Result()
		{
			return Expression.Result();
		}
		/// <summary>
		/// 获得简单表达式的XML内容
		/// </summary>
		/// <returns></returns>
		public override string GetXMLContent()
		{
			StringBuilder sb=new StringBuilder();

			sb.Append( Expression.ToXML() );

			return sb.ToString();
		}
		/// <summary>
		/// 转换为XML
		/// </summary>
		/// <param name="xmlnode"></param>
		/// <returns></returns>
		public static new  SimpleCondition FromXML( string xmlnode )
		{
			XObject xo=new XObject(xmlnode);

			SimpleCondition rtn=new SimpleCondition();

			rtn.Expression = BaseExpression.FromXML( xo.Childs[0].OuterXml );

			return rtn;
		}
	}
}
